<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>LAFDC: Authentification utilisateur</title>
   <link type="text/css" rel="stylesheet" href="skins/Style.css"/>
   <link type="text/css" rel="stylesheet" href="skins/forms.css"/>
   <script src="javascript/auth.js" type="text/javascript"></script>
   <script src="javascript/md5-m.js" type="text/javascript"></script>
   <style>
      #login_blk {
         border-style: solid;
         width:400px;
         height: 120px;
         margin-left:auto;
         margin-right:auto;
         padding: 15px;
      }
   </style>
</head>
<body>
   <div id="login_blk">
		<label>Utilisateur:</label><input type="text" id="uname"/><br/>
		<label>Mot de passe:</label><input type="password" id="psswd"/><br/>
      <p style="width:400px;">
	  <input type="Button" ID="login" value="Load cookie" OnClick="loadCookie()" style="width:100px;"/>&nbsp;
	  <input type="Button" ID="login" value="Save cookie" OnClick="saveCookie()" style="width:100px;"/>
	  <p>
   </div>
<script>
function saveCookie() {
   var p = document.getElementById("uname");
   var uname = p.value;

   p=document.getElementById("psswd");
   var psswd = p.value;

   var hash = hex_md5(uname + psswd + '\n');

   createCookie('lafdc-auth',hash);
   createCookie('sessionid',hex_md5(uname + psswd + '\n' + '34859345245'),'/lafdc/nosendcookie')
   //alert(readCookie('lafdc-auth'));
}
function loadCookie(){
   alert(readCookie('lafdc-auth'));
}

function createCookie(name,value,path) {
/*	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";*/
	var expires = "";
	if (path == null){
		path="; path=/";
	}
	else{
		path="; path=" + path;
	}
	document.cookie = name+"="+value+expires+path;
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

</script>
</body>
</html>
